package week1;

import org.apache.log4j.Logger;

/**
 * Created with IntelliJ IDEA.
 * User: golubinskyi
 * Date: 31.10.13
 * Time: 18:38
 * To change this template use File | Settings | File Templates.
 */
public class Sample2 {
    private static final Logger log = Logger.getLogger(Sample2.class);

    public Sample2() {
        log.info("Sample2 has been constructed");
        //TRACE
        //DEBUG
        //info
        //warn
        //error
        //fatal
    }

    public void testTrace() {
        log.trace("Sample2 - Trace invoked");
        for (int i = 0; i < 30; i++) {
            log.trace("iteration " + i);
        }
    }

    public void testDebug() {

        if (log.isDebugEnabled()) {
            log.debug("Sample2 - Debug invoked" + longOperation());
        }
    }

    private String longOperation() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        return "HEAVY OPERATION";
    }

    public void testInfo() {
        log.info("Sample2 - Info invoked");

    }
    public void testError() {
        log.error("Sample2 - Error invoked");
    }
    public void testWarn() {
        log.warn("Sample2 - Warn invoked");

    }
    public void testFatal() {
        log.fatal("Sample2 - Fatal invoked");

    }
    public void thisMayFail() throws Exception {
        throw new Exception("BOO");
    }
}
